﻿@page
@model AdminUI.Pages.SysManage.SysUserModel
@{
    var F = Html.F();
}

@section body {
    <f:Panel ID="Panel1" BodyPadding="5" ShowBorder="false" Layout="VBox" ShowHeader="false" Title="系统用户" IsViewPort="true">
        <Items>
            <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true" EnableMultiSelect="false" DataIDField="UserID" DataTextField="UserName"
                    AllowPaging="true" PageSize="@ViewBag.PageSize" IsDatabasePaging="true" OnPageIndexChanged="@Url.Handler("Grid_DoAction")" OnPageIndexChangedFields="Grid1"
                    AllowSorting="true" SortField="UserID" SortDirection="DESC" OnSort="@Url.Handler("Grid_DoAction")"
                    OnSortFields="Grid1" DataSource="@ViewBag.DataSource" RecordCount="@ViewBag.Total">
                <Toolbars>
                    <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                        <Items>
                            <f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnDelete" IconAlign="Left" EnableDefaultState="false" IconFont="TrashO" Text="删除" OnClientClick="onDeleteClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnChangeEnableUsers" IconAlign="Left" EnableDefaultState="false" IconFont="_Tag" Text="状态">
                                <Menu>
                                    <f:MenuButton ID="btnEnableUsers" Text="启用" OnClientClick="onEnableClick();"></f:MenuButton>
                                    <f:MenuButton ID="btnDisableUsers" Text="禁用" OnClientClick="onDisableClick();"></f:MenuButton>
                                </Menu>
                            </f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnResetPwd" IconAlign="Left" EnableDefaultState="false" IconFont="UnlockAlt" Text="重置密码" OnClientClick="onResetPwdClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="_Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                            <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
                            <f:DropDownList ID="Condition" SelectedValue="" Width="150">
                                <f:ListItem Text="== 请选择条件 ==" Value="" />
                                <f:ListItem Text="用户ID" Value="UserID" />
                                <f:ListItem Text="用户名" Value="UserName" />
                            </f:DropDownList>
                            <f:TriggerBox ID="Keyword" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Panel1">
                            </f:TriggerBox>
                        </Items>
                    </f:Toolbar>
                </Toolbars>
                <Columns>
                    <f:RenderField HeaderText="用户ID" DataField="UserID" QuickSortField="true" FieldType="Int" Width="90" TextAlign="Center" />
                    <f:RenderField HeaderText="租户" DataField="TID" FieldType="Int" Width="60" TextAlign="Center" />
                    <f:RenderField HeaderText="登录账号" DataField="UserName" Width="120" />
                    <f:RenderField HeaderText="类型" DataField="UserType" RendererFunction="renderUserType" FieldType="Int" Width="70" TextAlign="Center" />
                    <f:RenderField HeaderText="角色" DataField="RoleID" RendererFunction="renderRole" FieldType="Int" Width="120" />
                    <f:RenderField HeaderText="姓名" DataField="TrueName" Width="150" />
                    @*<f:RenderField HeaderText="身份证" DataField="IDCard" Width="160" Hidden="true" TextAlign="Center" />*@
                    <f:RenderField HeaderText="手机号" DataField="Mobile" Width="120" TextAlign="Center" />
                    <f:RenderField HeaderText="已登录" DataField="LoginCount" FieldType="Int" Width="80" TextAlign="Right" />
                    <f:RenderField HeaderText="上次登录" DataField="LastLoginTime" FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd HH:mm" Width="150" TextAlign="Center" />
                    <f:RenderCheckField HeaderText="启用" DataField="IsEnable" RenderAsStaticField="true" Width="50" TextAlign="Center" />
                    <f:RenderField HeaderText="关联门店ID" DataField="ShopID" FieldType="Int" Width="120" TextAlign="Center" />
                    <f:RenderField HeaderText="备注" DataField="Memo" Width="200" ExpandUnusedSpace="true" />
                </Columns>
                <PageItems>
                    <f:ToolbarSeparator></f:ToolbarSeparator>
                    <f:ToolbarText Text="每页记录数："></f:ToolbarText>
                    <f:DropDownList ID="ddlGridPageSize" Width="60" SelectedValue="@ViewBag.PageSize" OnSelectedIndexChanged="@Url.Handler("Grid_DoAction")" OnSelectedIndexChangedFields="Panel1">
                        <Items>
                            <f:ListItem Text="5" Value="5"></f:ListItem>
                            <f:ListItem Text="10" Value="10"></f:ListItem>
                            <f:ListItem Text="20" Value="20"></f:ListItem>
                            <f:ListItem Text="30" Value="30"></f:ListItem>
                            <f:ListItem Text="50" Value="50"></f:ListItem>
                            <f:ListItem Text="100" Value="100"></f:ListItem>
                            <f:ListItem Text="200" Value="200"></f:ListItem>
                        </Items>
                    </f:DropDownList>
                </PageItems>
            </f:Grid>
        </Items>
    </f:Panel>

    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="750" Height="500">
        @*<Listeners>
            <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
        </Listeners>*@
    </f:Window>
}

    @section script {

        <script src="~/res/js/grid.js"></script>
        <script>
          	//关闭弹窗后刷新当前页面
            @*function onWindowClose(actionType, actionParams) {
                var params = {
                    nodeId: 0
                };

                // 加入扩展参数
                if (actionType) {
                    params.actionType = actionType;
                }
                if (actionParams) {
                    $.extend(params, actionParams);
                }

                // 触发后台事件
                F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', params);
            }*@

        function onAddClick(event) {
            var path = "/SysManage/SysUserAdd";
            //showNotify(path);
            F.ui.Window1.show(path, '新增系统用户');
        }

        function onEditClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要修改的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/SysManage/SysUserEdit?id=" + selectedRow;
            //showNotify(path);
            F.ui.Window1.show(path, '修改系统用户');
        }

            function onResetPwdClick(event) {
                var grid1 = F.ui.Grid1;
                if (!grid1.hasSelection()) {
                    showNotify('请选择要重置密码的记录！');
                    return;
                }

                var selectedRow = grid1.getSelectedRow();
                var path = "/SysManage/ResetPwd?id=" + selectedRow;
                F.ui.Window1.show(path, '重置密码', 400, 300);
            }

        function onDeleteClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要删除的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要删除所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'delete',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onEnableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要启用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要启用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType:'enable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onDisableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要禁用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要禁用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType:'disable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

            function onRefreshClick() {
                F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1');
            }

            function renderRole(value, params) {
                if (value == -1) return "超级管理员";
                var dic = @Html.Raw(Json.Serialize(Model.Roles));
                if (dic[value]) {
                    return dic[value];
                }
                else {
                    return "-";
                }
            }
            //用户类型：1-平台，2-租户，3-门店
            function renderUserType(value, params) {
                switch (value) {
                    case 1:
                        return "<span class='tag-c1'>平台</span>";
                    case 2:
                        return "<span class='tag-c3'>租户</span>";
                    case 3:
                        return "<span class='tag-c4'>门店</span>";
                    default:
                        return "-";
                }
            }
        </script>
    }

